package cn.fl.insurance.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.DateUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.insurance.constant.InsuranceConstant;
import cn.fl.insurance.service.IInsChnOpenSettingService;
import cn.fl.insurance.service.IInsTypInfoService;
import cn.fl.insurance.vo.InsChnOpenSettingVO;
import cn.fl.insurance.vo.InsCompChnPolVO;
import cn.fl.insurance.vo.OrgTreeVO;
import cn.fl.insurance.vo.ReginTreeVO;
import cn.fl.preloan.condition.InsChnOpenSettingQueryCondition;
import cn.fl.preloan.dto.*;
import cn.fl.preloan.enums.PreloanResultCodeEnum;
import cn.fl.preloan.insurance.IInsChnOpenSettingsService;
import cn.fl.project.service.IPrjBscInfoService;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import cn.fl.commons.result.ResponseData;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @Description: 渠道放开设置表 控制层
 */
@Controller
@RequestMapping("/insurance/insChnOpenSetting")
public class InsChnOpenSettingController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(InsChnOpenSettingController.class);

    /**
     * InsChnOpenSetting 服务层BEAN
     */
    @Autowired
    private IInsChnOpenSettingService insChnOpenSettingService;
    @Autowired
    private IInsTypInfoService insTypInfoService;
    /**
     * 客户 服务层BEAN
     */
    @Autowired
    private ICstBscInfoService cstBscInfoService;

    @Autowired
    private IPrjBscInfoService prjBscInfoService;

    @Autowired
    private IInsChnOpenSettingsService insChnOpenSettingsService;

    /**
     * 到列表页面
     */
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toListPage", "加载InsChnOpenSetting列表页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("insurance/insChnOpenSetting/insChnOpenSettingList");
        this.prepare(request, mav, 1);
        return mav;
    }

    /**
     * 到新增页面
     */
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toAddPage", "加载InsChnOpenSetting Add页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("insurance/insChnOpenSetting/insChnOpenSettingModify");
        this.prepare(request, mav, 2);
        return mav;
    }

    /**
     * 到修改页面
     */
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger, "toModifyPage", "加载InsChnOpenSetting Modify页面.", CurrentThreadContext.getCurrentUserName());
        ModelAndView mav = new ModelAndView("insurance/insChnOpenSetting/insChnOpenSettingModify");
        this.prepare(request, mav, 2);
        String id = request.getParameter("id");
        GetInsChnOpenSettingRequest req = new GetInsChnOpenSettingRequest();
        req.setId(Long.valueOf(id));
         ResponseData data = this.insChnOpenSettingsService.selectById(req);
        InsChnOpenSettingVO insChnOpenSettingVO = new InsChnOpenSettingVO();
        BeanUtils.copyProperties(data.getData(),insChnOpenSettingVO);
        mav.addObject("insChnOpenSettingVO", insChnOpenSettingVO);
        if (insChnOpenSettingVO != null) {
            if (null != insChnOpenSettingVO.getExpBgDt()) {
                mav.addObject("expBgDts", DateUtils.formatDateToString(insChnOpenSettingVO.getExpBgDt(), DateUtils.YYYY_MM_DD));
            }
            if (null != insChnOpenSettingVO.getExpEndDt()) {
                mav.addObject("expEndDts", DateUtils.formatDateToString(insChnOpenSettingVO.getExpEndDt(), DateUtils.YYYY_MM_DD));
            }
        }

        return mav;
    }

    //加载数据字典数据、传值等 ？
    public void prepare(HttpServletRequest request, ModelAndView mav, int queryType) {
        List<KeyValueVO> prjTypCdList = null;
        //1 条件查询 展示所有
        if (Objects.equals(queryType, 1)) {
            prjTypCdList = prjBscInfoService.getPrjTypCdALLKV();
        } else {
            prjTypCdList = this.insChnOpenSettingService.searchCdList(InsuranceConstant.CODE_PRJ_TYP_CD);//项目类型
        }
        List<KeyValueVO> bizTypCdList = this.insChnOpenSettingService.searchCdList(InsuranceConstant.CODE_PRJ_BIZ_TYP_CD);//项目业务类型
        List<KeyValueVO> plcTypCdList = this.insChnOpenSettingService.searchCdList(InsuranceConstant.CODE_INS_PLC_NAT_CD);//保单类型 1.首年保单 2.续保保单
        List<KeyValueVO> insTypCdList = this.insChnOpenSettingService.searchCdList(InsuranceConstant.CODE_INS_TYP_CD);//保险种类
        /*InsTypInfoQueryCondition condition = new InsTypInfoQueryCondition();
        condition.setTypLvl(InsuranceConstant.CODE_INS_TYP_LVL_CD);//保险父类
        List<KeyValueVO> insTypCdList = this.insTypInfoService.searchInsTypCdList(condition);//保险种类*/
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        if (queryType == 1) {
            KeyValueVO kv = new KeyValueVO();
            kv.setKey("ALL");
            kv.setValue("全部");
            prjTypCdList.add(0, kv);
            bizTypCdList.add(0, kv);
            plcTypCdList.add(0, kv);
            insTypCdList.add(0, kv);
            orgList.add(0, kv);

            List<KeyValueVO> enableCdList = this.insChnOpenSettingService.searchCdList(InsuranceConstant.CODE_ENABLE_ON_OFF_CD);//起停标示
            mav.addObject("prjTypCdList", JSON.toJSONString(prjTypCdList));
            mav.addObject("bizTypCdList", JSON.toJSONString(bizTypCdList));
            mav.addObject("plcTypCdList", JSON.toJSONString(plcTypCdList));
            mav.addObject("enableCdList", JSON.toJSONString(enableCdList));
            mav.addObject("insTypCdList", JSON.toJSONString(insTypCdList));
            mav.addObject("buOrgCdList", JSON.toJSONString(orgList));
        } else {
            mav.addObject("prjTypCdList", "[{\"key\":\"ALL\",\"value\":\"全部\",\"children\":" + JSON.toJSONString(prjTypCdList) + "}]");
            mav.addObject("bizTypCdList", "[{\"key\":\"ALL\",\"value\":\"全部\",\"children\":" + JSON.toJSONString(bizTypCdList) + "}]");
            mav.addObject("plcTypCdList", "[{\"key\":\"ALL\",\"value\":\"全部\",\"children\":" + JSON.toJSONString(plcTypCdList) + "}]");
            mav.addObject("insTypCdList", "[{\"key\":\"ALL\",\"value\":\"全部\",\"children\":" + JSON.toJSONString(insTypCdList) + "}]");
            //mav.addObject("buOrgCdList", "[{\"key\":\"ALL\",\"value\":\"全部\",\"children\":" + JSON.toJSONString(orgList) + "}]");
        }
    }

    /**
     * 初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initInsChnOpenSettingList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        InsChnOpenSettingQueryCondition qc = new InsChnOpenSettingQueryCondition();
        String policyNm = request.getParameter("policyNm");
        String prjTypCd = request.getParameter("prjTypCd");
        String bizTypCd = request.getParameter("bizTypCd");
        String insTypCd = request.getParameter("insTypCd");
        String plcTypCd = request.getParameter("plcTypCd");
        String isValid = request.getParameter("isValid");
        String buOrgCd = request.getParameter("buOrgCd");
        if (StringUtils.isNotEmpty(policyNm)) {
            qc.setPolicyNm(policyNm.trim());
        }
        if (StringUtils.isNotEmpty(prjTypCd)) {
            qc.setPrjTypCd(prjTypCd);
        }
        if (StringUtils.isNotEmpty(bizTypCd)) {
            qc.setBizTypCd(bizTypCd);
        }
        if (StringUtils.isNotEmpty(insTypCd)) {
            qc.setInsTypCd(insTypCd);
        }
        if (StringUtils.isNotEmpty(plcTypCd)) {
            qc.setPlcTypCd(plcTypCd);
        }
        if (StringUtils.isNotEmpty(isValid)) {
            qc.setIsValid(Integer.parseInt(isValid));
        }
        if (StringUtils.isNotEmpty(buOrgCd)) {
            qc.setBuOrgCd(buOrgCd);
        }
        page.setCondition(qc);
        List<InsChnOpenSettingVO>  insChnOpenSettingVOList = new ArrayList<>();
        BaseLogUtils.info(logger, "initInsChnOpenSettingList", "初始化InsChnOpenSetting列表页面数据.DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        ResponseData<InsChnOpenSettingPageResponse> data = insChnOpenSettingsService.searchListPageByCondition(page.getCurrentPage(),page.getEveryPage(),qc);
        BaseLogUtils.newLogger("initInsChnOpenSettingList,初始化InsChnOpenSetting列表页面数据.RESULT:" + JSONObject.toJSONString(data), CurrentThreadContext.getCurrentUserName());
        List<InsChnOpenSettingDTO> insChnOpenSettingDTOList = data.getData().getInsChnOpenSettingDTOS();
        for(InsChnOpenSettingDTO insChnOpenSettingDTO :insChnOpenSettingDTOList){
            InsChnOpenSettingVO ins = new InsChnOpenSettingVO();
            BeanUtils.copyProperties(insChnOpenSettingDTO, ins);
            insChnOpenSettingVOList.add(ins);
        }
        ListPageVO<InsChnOpenSettingVO> listPage = new ListPageVO<InsChnOpenSettingVO>(insChnOpenSettingVOList, data.getData().getTotalCount());
        BaseLogUtils.info(logger, "initInsChnOpenSettingList", "初始化InsChnOpenSetting列表页面数据.DATA:" + JSONObject.toJSONString(listPage), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

    /**
     * 删除数据
     */
    @RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeInsChnOpenSettingByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "removeInsChnOpenSettingByIds", "删除InsChnOpenSetting数据,主键参数为空!", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }

        try {
            DeleteByIdsRequest req = new DeleteByIdsRequest();
            req.setIds(idsList);
            ResponseData data = insChnOpenSettingsService.deleteByIds(req);
            if (!data.getCode().equals(PreloanResultCodeEnum.SUCCESS.getCode())) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.info(logger, "removeInsChnOpenSettingByIds", "删除InsChnOpenSetting数据失败,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
            }
            BaseLogUtils.info(logger, "removeInsChnOpenSettingByIds", "删除InsChnOpenSetting数据成功,ID:" + idsList.toString(), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "removeInsChnOpenSettingByIds", "删除InsChnOpenSetting数据失败,ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "removeInsChnOpenSettingByIds", "删除InsChnOpenSetting数据失败,系统错误.ID:" + idsList.toString() + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 得到一条记录
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getInsChnOpenSettingById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.info(logger, "getInsChnOpenSettingById", "获取InsChnOpenSetting数据,主键参数为空.", CurrentThreadContext.getCurrentUserName());
            return result;
        }

        try {
            InsChnOpenSettingVO vo = new InsChnOpenSettingVO();
            GetInsChnOpenSettingRequest req = new GetInsChnOpenSettingRequest();
            req.setId(Long.valueOf(id));
            ResponseData data = insChnOpenSettingsService.selectById(req);
            BeanUtils.copyProperties(data.getData(),vo);
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.info(logger, "getInsChnOpenSettingById", "获取InsChnOpenSetting数据不存在,ID:" + id, CurrentThreadContext.getCurrentUserName());
            }
            result.setData(vo);
            BaseLogUtils.info(logger, "getInsChnOpenSettingById", "获取InsChnOpenSetting数据成功,ID:" + id, CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.info(logger, "getInsChnOpenSettingById", "获取InsChnOpenSetting数据失败,ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "getInsChnOpenSettingById", "获取InsChnOpenSetting数据失败,系统错误.ID:" + id + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addInsChnOpenSetting(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        InsChnOpenSettingVO entity = null;//获取参数
        try {
            entity = this.getRequestParamForInsChnOpenSetting(request);//获取参数
            AddInsChnOpenSettingRequest req = new AddInsChnOpenSettingRequest();
            InsChnOpenSettingDTO dto = new InsChnOpenSettingDTO();
            BeanUtils.copyProperties(entity,dto);
            req.setDto(dto);
            ResponseData data = insChnOpenSettingsService.addInsChnOpenSetting(req);
            result.setData(dto.getId());
            BaseLogUtils.info(logger, "addInsChnOpenSetting", "新增InsChnOpenSetting数据成功,ID:" + dto.getId() + ".DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "addInsChnOpenSetting", "新增InsChnOpenSetting数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "addInsChnOpenSetting", "新增InsChnOpenSetting数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyInsChnOpenSetting(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        InsChnOpenSettingVO entity = null;
        try {
            entity = this.getRequestParamForInsChnOpenSetting(request);
            if (entity.getId() == null) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.info(logger, "modifyInsChnOpenSetting", "修改InsChnOpenSetting信息,主键参数为空！.", CurrentThreadContext.getCurrentUserName());
                return result;
            }
            ModifyInsChnOpenSettingRequest req = new ModifyInsChnOpenSettingRequest();
            InsChnOpenSettingDTO dto = new InsChnOpenSettingDTO();
            BeanUtils.copyProperties(entity,dto);
            req.setDto(dto);
            ResponseData data = insChnOpenSettingsService.modifyChnOpenSetting(req);
            if (!data.getCode().equals(PreloanResultCodeEnum.SUCCESS.getCode())) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.info(logger, "modifyInsChnOpenSetting", "修改InsChnOpenSetting数据失败.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
                return result;
            }
            BaseLogUtils.info(logger, "modifyInsChnOpenSetting", "修改InsChnOpenSetting数据成功.DATA:" + JSONObject.toJSONString(entity), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.info(logger, "modifyInsChnOpenSetting", "修改InsChnOpenSetting数据失败.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.error(logger, "modifyInsChnOpenSetting", "修改InsChnOpenSetting数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) + ".ERROR:" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return result;
    }

    @RequestMapping(value = "/getRgnList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getRgnCdList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        //查询地区树
        List<ReginTreeVO> rgnList = this.insChnOpenSettingService.searchReginTreeVOList();
        return rgnList;
    }

    @RequestMapping(value = "/getOrgList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getOrgList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String orgId = request.getParameter("orgId");
        Long id = null;
        if (StringUtils.isNotBlank(orgId)) {
            id = Long.parseLong(orgId);
        }
        //查询地区树
        List<OrgTreeVO> orgList = this.insChnOpenSettingService.searchOrgTreeVOList(id);
        return orgList;
    }

    /**
     * 获取请求参数
     *
     * @param request 请求
     * @return
     */
    private InsChnOpenSettingVO getRequestParamForInsChnOpenSetting(HttpServletRequest request) throws BaseException {
        //获取参数
        String id = request.getParameter("id");//主键
        String policyNm = request.getParameter("policyNm");//政策名称
        String expBgDt = request.getParameter("expBgDt");//有效期开始日期
        String expEndDt = request.getParameter("expEndDt");//有效期结束日期
        String buOrgCd = request.getParameter("buOrgCd");//适用事业部
        String prjTypCd = request.getParameter("prjTypCd");//适用项目类型PRJ0002
        String bizTypCd = request.getParameter("bizTypCd");//适用项目业务类型PRJ0006
        String rgnCd = request.getParameter("rgnCd");//适用区域
        String plcTypCd = request.getParameter("plcTypCd");//适用保单类型INS0003
        String insTypCd = request.getParameter("insTypCd");//适用险种
        String settingRem = request.getParameter("settingRem");//备注
        String status = request.getParameter("isValid");

        //验证参数并赋值
        InsChnOpenSettingVO entity = new InsChnOpenSettingVO();
        if (StringUtils.isBlank(id) && StringUtils.isBlank(policyNm)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "名称不能为空.");
        }
        entity.setPolicyNm(policyNm);//政策名称
        if (StringUtils.isNotBlank(expBgDt)) {
            entity.setExpBgDt(DateUtils.formatStringToDate(expBgDt, DateUtils.YYYY_MM_DD));//有效期开始日期
        }
        if (StringUtils.isNotBlank(expEndDt)) {
            entity.setExpEndDt(DateUtils.formatStringToDate(expEndDt, DateUtils.YYYY_MM_DD));//有效期结束日期
        }
        if (StringUtils.isNotBlank(buOrgCd)) {
            entity.setBuOrgCd(buOrgCd + ";");//适用事业部
        }
        if (StringUtils.isNotBlank(prjTypCd)) {
            entity.setPrjTypCd(prjTypCd + ";");//适用项目类型PRJ0002
        }
        if (StringUtils.isNotBlank(bizTypCd)) {
            entity.setBizTypCd(bizTypCd + ";");//适用项目业务类型PRJ0023
        }
        if (StringUtils.isNotBlank(rgnCd)) {
            entity.setRgnCd(rgnCd + ";");//适用区域
        }
        if (StringUtils.isNotBlank(plcTypCd)) {
            entity.setPlcTypCd(plcTypCd + ";");//适用保单类型INS0003
        }
        if (StringUtils.isNotBlank(insTypCd)) {
            entity.setInsTypCd(insTypCd + ";");//适用险种
        }

        entity.setSettingRem(settingRem);//备注
        if (StringUtils.isNotEmpty(status)) {
            entity.setIsValid(Integer.parseInt(status));
        }

        Date tm = new Date();
        if (StringUtils.isNotBlank(id)) {
            entity.setId(Long.valueOf(id));
            entity.setMdfTm(tm);
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
        } else {
            entity.setCrtTm(tm);
            entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        }

        return entity;
    }
}

